package htfile

import (
	"core/corestruct"
	"core/server/kafkaserver"
	"encoding/json"
	"github.com/dubbogo/gost/log/logger"
	kafkago "github.com/segmentio/kafka-go"
	"ht/service/htfile"
)

var (
	htFilerevServer *kafkaserver.ConsumerServer
)

func init() {

	htFilerevServer = &kafkaserver.ConsumerServer{
		Name:    "文件上传推送",
		Topic:   TOPIC_HTFILE_UP,
		GroupID: TOPIC_HTFILE_UP,
	}
	htFilerevServer.Do = htFilerevServerDo
	htFilerevServer.Start()
}
func htFilerevServerDo(message kafkago.Message) error {
	//生成conver
	//生产show
	var m = &corestruct.IdNameDto{}
	err := json.Unmarshal(message.Value, m)
	if err != nil {
		logger.Error(err)
		return err
	}
	var svr = &htfile.HtfileService{}
	mfile, err := svr.Get(m.Id)
	if err != nil {
		logger.Error(err)
		return err
	}
	err = svr.SaveCover(mfile)
	if err != nil {
		logger.Error(err)
		return err
	}
	logger.Infof("保存封面 %v 成功", mfile.Name)
	err = svr.SavePdfShow(mfile)
	if err != nil {
		logger.Error(err)
		return err
	}
	logger.Infof("保存预览 %v 成功", mfile.Name)
	return nil
}
